﻿package com.PlantVsZombies.common;

import java.util.UUID;


/**
 * runnable基类
 * @author wangdongdong
 *
 */
public abstract class Life extends Thread{
	String control = "";
	boolean suspend = false;
	boolean isLive = true; // 当前状态

	public void setSuspend(boolean suspend) {
		if (!suspend) {
			synchronized (control) {
				control.notifyAll();
			}
		}
		this.suspend = suspend;
	}

	public void run() {
		try {
			while (true) {
				synchronized (control) {
					if (suspend) {
						control.wait();
					}
				}
				if (this.doRun() == 0)
					return;
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	public abstract int doRun();

	public boolean isLive() {
		return isLive;
	}

	public void setLive(boolean isLive) {
		this.isLive = isLive;
	}

	public boolean isSuspend() {
		return suspend;
	}

}
